/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package VLCPlayerComponent;

import PlayerComponent.JPlayerReport;
import java.awt.KeyEventPostProcessor;
import java.awt.KeyboardFocusManager;
import java.awt.Window;
import java.awt.event.KeyEvent;

/**
 *
 * @author wcss
 */
public class VLCFullScreenFrame extends VLCFrame implements JPlayerReport {

    KeyboardFocusManager keyManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    MyKeyEventPostProcessor currentProcessor = null;
    
    /**
     * Creates new form VLCFullScreenFrame
     */
    public VLCFullScreenFrame() {
        initComponents();
        this.getGraphicsConfiguration().getDevice().setFullScreenWindow(this);
        this.setAlwaysOnTop(true);
        this.vLCMediaPlayer1.playerEvents = this;
        this.vLCMediaPlayer1.initPlayer();
        this.vLCMediaPlayer1.showPlayer();
        frmExitWithVK_ESC(this);
    }

    public VLCMediaPlayer getMediaPlayer() {
        return this.vLCMediaPlayer1;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        vLCMediaPlayer1 = new VLCPlayerComponent.VLCMediaPlayer();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                formComponentResized(evt);
            }
        });
        addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                formKeyPressed(evt);
            }
        });
        getContentPane().setLayout(null);

        vLCMediaPlayer1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                vLCMediaPlayer1KeyPressed(evt);
            }
        });
        getContentPane().add(vLCMediaPlayer1);
        vLCMediaPlayer1.setBounds(12, 12, 261, 170);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        // TODO add your handling code here:
        this.getMediaPlayer().stopPlay();
        if (currentProcessor != null)
        {
            keyManager.removeKeyEventPostProcessor(currentProcessor);
        }
    }//GEN-LAST:event_formWindowClosed

    private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized
        // TODO add your handling code here:
        this.vLCMediaPlayer1.setLocation(0, 0);
        this.vLCMediaPlayer1.setSize(this.getWidth(), this.getHeight());
        this.vLCMediaPlayer1.showPlayer();
    }//GEN-LAST:event_formComponentResized

    private void formKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formKeyPressed
        // TODO add your handling code here:
        //System.out.println(evt.getKeyCode());
    }//GEN-LAST:event_formKeyPressed

    private void vLCMediaPlayer1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_vLCMediaPlayer1KeyPressed
        // TODO add your handling code here:
        //System.out.println(evt.getKeyCode());
    }//GEN-LAST:event_vLCMediaPlayer1KeyPressed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private VLCPlayerComponent.VLCMediaPlayer vLCMediaPlayer1;
    // End of variables declaration//GEN-END:variables

    @Override
    public void reportPlayProgress(Object sender, int percent) {
        if (percent >= 99) {
            this.dispose();
        }
    }

    public void frmExitWithVK_ESC(Window frame)
    {   
        currentProcessor = new MyKeyEventPostProcessor(frame);
        keyManager.addKeyEventPostProcessor(currentProcessor);
    }

    class MyKeyEventPostProcessor implements KeyEventPostProcessor {

        Window frame;

        private MyKeyEventPostProcessor(Window f) {
            frame = f;
        }

        public boolean postProcessKeyEvent(KeyEvent ke) {
            if (ke.getKeyCode() == KeyEvent.VK_ESCAPE) {
                frame.dispose();
            }
            return true;
        }
    ;

    }  
    
    @Override
    public void reportPlayAction(Object sender, String actionName) {
    }
}
